package cn.tuling;

import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @Author: LDeng
 * @Date: 2021-06-28 16:54
 */
public class VolatileSeriaTest {

    static int x=0,y=0;
    static int a=0,b=0;

    public static void main(String[] args) throws InterruptedException {
        Set<String> resultSet=new HashSet<>();

        Executors.newCachedThreadPool();
        Executors.newFixedThreadPool(1);
        Executors.newSingleThreadExecutor();


        for (int i = 0; i < 1000000; i++) {
            x=0;
            y=0;
            a=0;
            b=0;

            Thread t1=new Thread(()->{
              a=y;
              x=1;
            });
            Thread t2=new Thread(()->{
                b=x;
                y=1;
            });

            t1.start();
            t2.start();
            t1.join();
            t2.join();

            resultSet.add("a="+a+","+"b="+b);
            System.out.println(resultSet);
        }
    }

}
